package com.tieto.user.bean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import com.tieto.user.dto.User;
import com.tieto.user.service.UserManagement;

import lombok.Data;

@ManagedBean(name="registerBean")
@RequestScoped
@Data
public class RegisterBean {
	private User user = new User();
	@ManagedProperty(value="#{userManagement}")	
	private UserManagement userManagement;

	public String register() {
		if (!userManagement.exists(user.getPassword())) {
			userManagement.save(user);
		}else {
			// TODO show error message
		}
		user = new User();
		return "userAdded";
	}
}
